package com.hdaccp.cloud.Controller;


import com.hdaccp.cloud.bean.Users;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;


@RestController
public class UsersConsumerController {


    @Autowired
    private RestTemplate restTemplate ;
    @HystrixCommand(fallbackMethod = "defaultFallback")
    @RequestMapping("/getConsumerUsers/{id}")
    public Users getUsers(@PathVariable("id") int id){
      Users users=  restTemplate.getForObject("http://T170CLOUD/getUsers/"+id,Users.class);
        return users;
    }


    @RequestMapping("/queryConsumerUsers")
    public List<Users> query(){
        List<Users> list=  restTemplate.getForObject("http://T170CLOUD/queryUsers/",List.class);
        return list;
    }

    public Users defaultFallback(int id){
        Users users =new Users();
        users.setId(0);
        users.setName("二蛋");
        users.setAddress("河北");
        return  users;
    }
}
